<template>
    <div class="employee-create-template">
        <el-button class="return" type="text" @click="jumpToDefault"><i class="fa fa-angle-left mr5"></i>返回</el-button>
        <h4 class="header">创建员工信息</h4>
        <div class="content">
            <div class="filter-section">
                <span class="fl title">员工基本信息</span>
                <span class="fr gray">注：带有*为必填项</span>
            </div>
            <div class="employee-form">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                    <el-form-item label="部门" prop="department">
                        <el-select v-model="ruleForm.department" placeholder="请选择部门" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="员工姓名" prop="name">
                        <el-input v-model="ruleForm.name" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="员工工号" prop="workNo">
                        <el-input v-model="ruleForm.workNo" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="岗位名称" prop="jobName">
                        <el-input v-model="ruleForm.jobName" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="性别" prop="sex">
                        <el-radio-group v-model="ruleForm.sex" size="mini">
                            <el-radio label="1">男</el-radio>
                            <el-radio label="0">女</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="工作电话" prop="workPhone">
                        <el-input v-model="ruleForm.workPhone" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号码" prop="telephone">
                        <el-input v-model="ruleForm.telephone" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="邮箱" prop="email">
                        <el-input v-model="ruleForm.email" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="工作QQ" prop="workQQ">
                        <el-input v-model="ruleForm.workQQ" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="短号" prop="cornet">
                        <el-input v-model="ruleForm.cornet" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="职位级别" prop="jobLevel">
                        <el-select v-model="ruleForm.jobLevel" placeholder="请选择职位级别" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="职位类别" prop="plantCategory">
                        <el-select v-model="ruleForm.plantCategory" placeholder="请选择职位类别" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="员工状态" prop="employeeStatue">
                        <el-select v-model="ruleForm.employeeStatus" placeholder="请选择员工状态" size="mini">
                            <el-option label="正常" value="1"></el-option>
                            <el-option label="异常" value="0"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="是否离职" prop="isLeave">
                        <el-radio-group v-model="ruleForm.isLeave" size="mini">
                            <el-radio label="1">是</el-radio>
                            <el-radio label="0">否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="分配状态" prop="allcateState" class="fl">
                        <el-select v-model="ruleForm.allcateState" placeholder="请选择分配状态" size="mini">
                            <el-option label="未分配" value="0"></el-option>
                            <el-option label="已分配" value="1"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="岗位职责" prop="jobRespon" class="form-textarea">
                        <el-input type="textarea" v-model="ruleForm.jobRespon" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" prop="note" class="form-textarea">
                        <el-input type="textarea" v-model="ruleForm.note" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
                        <el-button @click="cancelForm()">取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "EmployeeCreate",
        data() {
            return {
                ruleForm: {
                    department: "",
                    name: "",
                    workNo: "",
                    jobName: "",
                    jobRespon: "",
                    sex: "0",
                    workPhone: "",
                    telephone: "",
                    email: "",
                    workQQ: "",
                    cornet: "",
                    jobLevel: "",
                    plantCategory: "",
                    employeeStatus: "",
                    isLeave: "0",
                    allcateState: "",
                    note: ""
                },
                rules: {
                    department: [
                        {required: true, message: '请选择部门', trigger: 'change'},
                    ],
                    name: [
                        {required: true, message: '请输入员工姓名', trigger: 'blur'}
                    ],
                    workNo: [
                        {required: true, message: '请输入员工工号', trigger: 'blur'},
                        {type: 'number', message: '员工工号必须为数字', trigger: 'change'}
                    ],
                    jobName: [
                        {required: true, message: '请输入岗位名称', trigger: 'blur'}
                    ],
                    sex: [
                        {required: true, message: '请选择性别', trigger: 'change'},
                    ],
                    workPhone: [
                        {required: true, message: '请输入工作电话', trigger: 'blur'},
                        {type: 'number', message: '工作电话必须为数字', trigger: 'change'}
                    ],
                    telephone: [
                        {required: true, message: '请输入手机号码', trigger: 'blur'},
                        {type: 'number', message: '手机号码必须为数字', trigger: 'change'}
                    ],
                    email: [
                        {required: true, message: '请输入邮箱地址', trigger: 'blur'},
                        {type: 'email', message: '请输入正确的邮箱地址', trigger: 'change'}
                    ],
                    workQQ: [
                        {required: true, message: '请输入工作QQ', trigger: 'blur'},
                        {type: 'number', message: 'QQ必须为数字', trigger: 'change'}
                    ],
                    jobLevel: [
                        {required: true, message: '请选择职位级别', trigger: 'change'},
                    ],
                    plantCategory: [
                        {required: true, message: '请选择职务类别', trigger: 'change'},
                    ],
                    employeeStatus: [
                        {required: true, message: '请选择员工状态', trigger: 'change'},
                    ],
                    isLeave: [
                        {required: true, message: '请选择是否离职', trigger: 'change'},
                    ],
                    allcateState: [
                        {required: true, message: '请选择分配状态', trigger: 'change'},
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        console.log('submit!');
                        this.jumpToDefault();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            cancelForm() {
                this.jumpToDefault();
            },
            jumpToDefault() {
                this.$parent.curPath = 'default';
            }
        }
    }
</script>

<style lang="scss">
    @import "src/common/common.style";
    .employee-create-template {
        background-color: #ffffff;
        width: 100%;
        height: 100%;
        position: relative;
        .return{
            position: absolute;
            top: 0;
            left: 15px;
            padding: 0;
        }
        .header {
            text-align: center;
        }
        .content {
            height: 100%;
            .filter-section {
                border-bottom: 1px solid #ddd;
                padding-bottom: 25px;
                margin: 0 10px;
                padding-left: 5px;
                padding-right: 5px;
                .title {
                    font-size: $font-mn;
                    font-weight: 600;
                }
                .gray {
                    color: gray;
                }
            }
            .employee-form {
                height: 100%;
                padding-top: 10px;
                .el-form {
                    height: calc(100% - 120px);
                    @include ofy-a();
                    margin: 0 50px;
                    .el-form-item:not(.form-textarea) {
                        display: inline-block;
                        width: 50%;
                        margin-bottom: 15px;
                        .el-form-item__content {
                            @include fl();
                            margin-left: 0 !important;
                        }
                        .el-input {
                            width: 300px;
                        }
                    }
                    .form-textarea {
                        clear: both;
                        .el-textarea {
                            width: 80%;
                            float: left;
                            .el-textarea__inner {
                                min-height: 100px !important;
                            }
                        }
                    }
                    .el-button {
                        width: 100px;
                        margin: 0 50px;
                    }
                }
            }
        }
    }
</style>